package com.hrc.springboot.bean;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 配置文件中的配置信息加载到配置文件中
 * @ConfigurationProperties: 告诉SpringBoot中所有的属性和配置文件中相关的所有属性和配置文件进行绑定
 * 在这个注解中有一个属性是 prefix = "person"配置文件中的某一个主键下面的属性进行一一映射
 * 如果要想使用这些数据，就需要进行IOC
 */
@Component
@ConfigurationProperties(prefix = "person") // 默认从全局配置文件获取
@Validated
// @PropertySource("classpath:person.properties")
public class Person {
//    @Email
    private String name;
    //@Value("${person.age}")
    private Integer age;
    //@Value("${person.boss}")
    private Boolean boss;
    //@Value("${person.birth}")
    private Date birth;

    private Map<String, Object> map;
    //@Value("${person.list}")
    private List<Object> list;
    private Dog dog;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Boolean getBoss() {
        return boss;
    }

    public void setBoss(Boolean boss) {
        this.boss = boss;
    }

    public Date getBirth() {
        return birth;
    }

    public void setBirth(Date birth) {
        this.birth = birth;
    }

    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }

    public List<Object> getList() {
        return list;
    }

    public void setList(List<Object> list) {
        this.list = list;
    }

    public Dog getDog() {
        return dog;
    }

    public void setDog(Dog dog) {
        this.dog = dog;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", boss=" + boss +
                ", birth=" + birth +
                ", map=" + map +
                ", list=" + list +
                ", dog=" + dog +
                '}';
    }
}
